package com.example.polarity;

import java.util.Random;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;

public class Stars extends View
{

	int ScreenWidth = 0;
	int ScreenHeight = 0;
	
	Random randomNumber; 
	Paint paint;
	
	int DrawCount = 60;
	int DrawCount2 = 25;
	boolean init = true;
	
	
	BlinkingStar[] stars = new BlinkingStar[100];
	
	public Stars(Context context) 
	{	
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	@SuppressLint("NewApi")
	public Stars(Context context, AttributeSet attrs) 
	{
		super(context, attrs);
		this.setWillNotDraw(false);
		DisplayMetrics metrics = context.getResources().getDisplayMetrics();
		ScreenWidth  = metrics.widthPixels;
		ScreenHeight = metrics.heightPixels;
		randomNumber = new Random();
		paint = new Paint();
		
		 for(int i = 0; i <  stars.length; i++)
		 {
			 int cx = randomNumber.nextInt(ScreenWidth);
			 int cy = randomNumber.nextInt(ScreenHeight);
			 
			 BlinkingStar s =  new BlinkingStar(Color.WHITE, cx, cy, 1);
			 stars[i] = s;
			 
		 }
		
		
	}
	
	public Stars(Context context, AttributeSet attrs, int defStyle) 
	{
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	 @SuppressLint("NewApi")
	 @Override
	 protected void onDraw(Canvas canvas) 
	 {

		 for(int i = 0; i <  stars.length; i++)
		 {
			 int ranNum = randomNumber.nextInt(stars.length );
			 
			 if(ranNum != i)
			 {
				 
				 paint.setColor(stars[i].color);
				 canvas.drawCircle(stars[i].cx, stars[i].cy, stars[i].radius, paint); 
			 }
		 }
		 
		invalidate();
	 }
}
